/**
 * @copyright (C) COPYRIGHT 2022 Fortiortech Shenzhen
 * @file      xxx.c
 * @author    Fortiortech  Appliction Team
 * @date      2022-07-13
 * @brief     This file contains TSD function used for Motor Control.
 */

#include <SMDU.h>
/********************************************************************************
    Internal Routine Prototypes
********************************************************************************/

/*  -------------------------------------------------------------------------------------------------
    Function Name  : HW_One_PI
    Description    : PI
    Date           : 2021-08-08
    Parameter      : Xn1: [输入]
    ------------------------------------------------------------------------------------------------- */
int16 HW_One_PI(int16 Xn1)
{
    PI1_EK = Xn1; // 填入EK
    SMDU_RunBlock(1, PI);
    return PI1_UKH;
}

/*  -------------------------------------------------------------------------------------------------
    Function Name  : LPFFunction
    Description    : 低通滤波函数
    Date           : 2021-08-08
    Parameter      : Xn1: [输入]
**                   Xn0: [输入]
**                   K: [输入]
    ------------------------------------------------------------------------------------------------- */
int16 LPFFunction(int16 Xn1, int16 Xn0, int8 K)
{
    LPF0_K = K << 8;
    LPF0_X = Xn1;
    LPF0_YH = Xn0;
    SMDU_RunBlock(0, LPF);
    return LPF0_YH;
}

/*  -------------------------------------------------------------------------------------------------
    Function Name  : Atan_Us_MDU
    Description    : XX-XX-XX
    Date           : 2021-11-06
    Parameter      : Xn1: [输入/出]
**                 Xn0: [输入/出]
**                 K: [输入/出]
    ------------------------------------------------------------------------------------------------- */
int16 Atan_Us_MDU(int16 Xn1, int16 Xn0)
{
    SCAT1_COS = Xn1;
    SCAT1_SIN = Xn0;
    SCAT1_THE = 0;
    SMDU_RunBlock(1, ATAN);
    return SCAT1_RES1;
}

/*  -------------------------------------------------------------------------------------------------
    Function Name  : Atan_Us_MDU
    Description    : XX-XX-XX
    Date           : 2021-11-06
    Parameter      : Xn1: [输入/出]
**                       Xn0: [输入/出]
**                       Yn:  [输入/出]
    ------------------------------------------------------------------------------------------------- */
int16 DivQ_L_MDU(uint16 Xn1, uint16 Xn0, uint16 Yn)
{
    DIV0_DAH = Xn1;
    DIV0_DAL = Xn0;
    DIV0_DB = Yn;
    SMDU_RunBlock(0, DIV);
    return DIV0_DQL;
}
